clear all;
close all;

A=imread('cameraman.tif');

yPsnr = zeros(81);
yH = zeros(81);
yTaux = zeros(81);

for i = 1:81
    I=jpeg('cameraman.tif', i+9);
    F = A - I;
    [x,y]=size(F);
    mse2=sum(sum(F.*F))/(x*y);
    yPsnr(i)=10*log10(255*255/mse2);
    
    I2 = double(I);
    freq = hist(I2(:), 256);
    [x, y] = size(I2);
    prob = freq/(x*y);
    pos = find(prob);
    yH(i) = -sum(prob(pos).*log2(prob(pos)));
    
    imwrite(I,'tmp.jpeg','JPEG','Quality',i+9);
    infoA = imfinfo('cameraman.tif');
    infoB = imfinfo('tmp.jpeg');
    yTaux(i) = double(infoA.FileSize)/double(infoB.FileSize);
end

subplot(3,1,1), plot(10:1:90,yPsnr);
subplot(3,1,2), plot(10:1:90,yH);
subplot(3,1,3), plot(10:1:90,yTaux);
